unit EditMagazines;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, IBQuery, Db, DBCtrls, Menus, Mask;

type
  TfmMagEdit = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    btnSave: TButton;
    DBEdit1: TDBEdit;
    DBEdit2: TDBEdit;
    DBEdit3: TDBEdit;
    DBEdit4: TDBEdit;
    DBEdit5: TDBEdit;
    DataSource1: TDataSource;
    Label6: TLabel;
    DBEdit6: TDBEdit;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btnSaveClick(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
    FSaved: boolean;
    FQuery: TIBQuery;
    procedure SetQuery(Qry: TIBQuery);
  public
    { Public declarations }
    property Query: TIBQuery read FQuery write SetQuery;
  end;

var
  fmMagEdit: TfmMagEdit;

implementation

uses DataModule, Biblio;
{$R *.DFM}

procedure TfmMagEdit.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if not FSaved then begin
    FQuery.Cancel;
    FQuery.CancelUpdates;
  end;
  FQuery.Transaction.CommitRetaining;
  Action := caFree;
end;

procedure TfmMagEdit.SetQuery(Qry: TIBQuery);
begin
  FQuery := Qry;
  DataSource1.DataSet := Qry;
end;

procedure TfmMagEdit.btnSaveClick(Sender: TObject);
var
  otd: string;
  kod: integer;
begin
  otd := FQuery.FieldByName('OTDEL').AsString;
  kod := Kod_otd(otd);
  FQuery.FieldByName('RAZDEL').AsInteger := kod;
  FQuery.ApplyUpdates;
  FSaved := True;
  Close;
end;

procedure TfmMagEdit.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #27 then Close;
  if Key = #13 then
    FindNextControl(ActiveControl, True, True, True).SetFocus;
end;

end.
